package com.smarth.zhizulian.jsinter;

import android.app.Activity;
import android.content.Context;
import android.webkit.JavascriptInterface;

import com.smarth.zhizulian.activity.MainActivity;
import com.smarth.zhizulian.bean.activity.ActivityShare;
import com.smarth.zhizulian.http.KumaHttp;
import com.smarth.zhizulian.http.observer.ProgressObserver;
import com.smarth.zhizulian.http.utils.RxCompos;
import com.smarth.zhizulian.utils.KumaDialogFactory;
import com.smarth.zhizulian.utils.ShareUtils;

import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;

/**
 * Created by 18865 on 2018/1/26.
 */

public class JSActivityInterface {
    private Context mContext;

    public JSActivityInterface(Context context) {
        this.mContext = context;
    }

    @JavascriptInterface
    public void share() {
        KumaHttp.getService().activityShare()
                .compose(RxCompos.<ActivityShare>getBELoginCompos())
                .subscribe(new ProgressObserver<ActivityShare>(mContext) {
                    @Override
                    public void onNext(ActivityShare activityShare) {
//                        ShareUtils.shareActivityResult(mContext, activityShare.getMoeny(), activityShare.getShareUrl(), Wechat.NAME);
                        KumaDialogFactory.buildActivityShareDialog((Activity) mContext, activityShare);
                    }
                });
    }

    @JavascriptInterface
    public void goInvite() {
        MainActivity.openClearTask(mContext, MainActivity.MODE_DISCIPLE);
    }
}
